当前位置: 首页 > news >正文

印刷设计公司起名seo营销外包

印刷设计公司起名,seo营销外包,win7 做网站服务器,给自己的家乡建设网站流程控制语句 在计算机编程中,控制程序流程是算法设计中的一个核心概念,它使得程序能够根据特定条件执行不同的操作或重复执行某段代码。这显著增强了计算机算法相对于简单数学公式的功能和灵活性。 if语句 在单个 if 语句中只有当测试表达式&#xff0…

流程控制语句

 在计算机编程中,控制程序流程是算法设计中的一个核心概念,它使得程序能够根据特定条件执行不同的操作或重复执行某段代码。这显著增强了计算机算法相对于简单数学公式的功能和灵活性。

if语句

 在单个 if 语句中只有当测试表达式(angle<90.0)为真时,结构内的代码才会执行。

program testimplicit noneinteger :: angle = 80if ( long < 90 ) thenprint *, "angle is less than 90"end ifend program test

if-else语句

在如 if 等结构内缩进代码是一种良好的编程习惯,可以提高代码的可读性。我们可以使用关键字 else 为结构添加一个备选分支。

program testimplicit noneinteger :: ageprint *, "Enter your age:"read *, ageif (age > 18) thenprint *, "You are Old B."else if (age .eq. 18) thenprint *, "You are an adult."elseprint *, "You are a little B."end ifend program test

循环结构do

循环具有一个整数计数器变量,用于跟踪当前正在执行的循环迭代。在此示例中,我们为此计数器变量使用了一个通用名称:do 循环中的 i

当我们定义循环的开始时,使用计数器变量名后跟等号(=)来指定计数变量的起始值和最终值。

program testimplicit noneinteger :: ido i = 1, 10print *, iend doend program test

带跳步的do循环 

 我们只需要在循环条件末尾设置跳步的步数即可。

program testimplicit noneinteger :: ido i = 1, 10, 2print *, i  ! Print odd numbersend doend program test

条件循环(do while)

可以使用关键字 do while 向循环添加条件。只要给定的条件评估为真,循环就会执行。

program testimplicit noneinteger :: ii = 1do while (i < 11)print *, ii = i + 1end doend program test

循环控制语句(exit 、cycle)

通常情况下,如果满足某个条件,需要停止循环。Fortran 提供了两个可执行语句来处理这种情况。需要注意的是,在嵌套循环中使用时,cycle 和 exit 语句作用于最内层的循环。

exit 用于提前退出循环。它通常包含在 if 语句内。

program testimplicit noneinteger :: ido i = 1, 100if (i > 10) thenexit  ! Stop printing numbersend ifprint *, iend doend program test

另一方面,cycle 会跳过循环中剩余的部分,并进入下一个循环周期 。

program testimplicit noneinteger :: ido i = 1, 10if (mod(i, 2) == 0) thencycle  ! Don't print even numbersend ifprint *, iend doend program test

嵌套循环控制:标签

在任何编程语言中,嵌套循环都是一个常见的情况。嵌套循环指的是存在于另一个循环内的循环。Fortran 允许程序员为每个循环添加标签或名称。如果为循环添加了标签,则有两个潜在的好处:

  1. 可以提高代码的可读性(当命名有意义时)。
  2. 可以使用带标签的 exit 和 cycle,从而实现对循环的精细控制。
program testimplicit noneinteger :: i, jinteger :: sum_limit = 15logical :: found = .false.! 外层循环,带有标签outer_loopouter_loop: do i = 1, 10! 内层循环,带有标签inner_loopinner_loop: do j = 1, 10if (i + j > sum_limit) then! 如果和超过了限制,跳出内层循环的当前迭代cycle inner_loopend ifprint *, 'i =', i, 'j =', j, 'sum =', i + j! 如果需要在特定的和后想要退出所有循环if (i + j == 10) then! 设置标志变量表示已找到found = .true.! 退出外层循环exit outer_loopend ifend do inner_loopend do outer_loop! 根据是否找到特定的和,打印相应的消息if (found) thenprint *, 'Found a pair (i, j) whose sum is 10.'elseprint *, 'Did not find any pair (i, j) whose sum is 10.'end ifend program test

可并行化循环(do concurrent)

do concurrent 循环用于明确指定循环内部没有相互依赖关系;这告诉编译器可以使用并行化/SIMD 来加速循环的执行,并更清晰地传达程序员的意图。更具体地说,这意味着任何给定的循环迭代都不依赖于其他循环迭代的先前执行。同时,任何可能发生的状态变化都必须仅在每个循环内部发生。这些要求对可以放在循环体内的内容施加了限制。

简单地用 do concurrent 替换一个循环并不能保证并行执行。上述解释并没有详细说明编写正确 do concurrent 循环所需满足的所有要求。编译器也可以自行决定如何优化(例如,对于执行简单计算且迭代次数较少的循环,如以下示例),这意味着它们可能不会优化循环。通常,需要编译器标志来激活循环的可能并行化。

program testimplicit noneinteger :: iinteger, parameter :: n = 1000real, dimension(n) :: a, b, c! 初始化数组a和ba = 1.0b = 2.0do concurrent (i = 1:n)c(i) = a(i) + b(i)end do! 打印数组的前10个元素以验证结果print *, 'First 10 elements of array c:'do i = 1, 10print *, c(i)end doend program test

操作符

编程中,逻辑表达式用于评估和比较值,以确定条件是否为真。构建逻辑表达式时,可以使用关系运算符和逻辑运算符。

关系运算符

关系运算符用于比较两个值,并返回一个布尔结果(真或假)。 

操作符  

选择  

描述

==

.eq.

测试两个操作数是否相等

/=

.ne.

测试两个操作数是否不相等

>

.gt.

测试左操作数是否严格大于右操作数

<

.lt.

测试左操作数是否严格小于右操作数

>=

.ge.

测试左操作数是否大于或等于右操作数

<=

.le.

测试左操作数是否小于或等于右操作数

program testimplicit noneinteger :: iinteger :: jprint *, "Enter First Integers"read *, iprint *, "Enter Second Integers"read *, jif (i .eq. j) thenprint *, "i = j"else if (i .ne. j) thenprint *, "i != j"if (i .gt. j) thenprint *, "i > j"else if (i .lt. j) thenprint *, "i < j"end ifend ifif (i .ge. j) thenprint *, "i >= j"end ifif (i .le. j) thenprint *, "i <= j"end ifend program test

逻辑运算符

逻辑运算符用于组合或反转布尔表达式,从而构建更复杂的条件。

操作符  

描述

.and.

如果左右操作数都为 TRUE,则为 TRUE

.or.

如果左侧或右侧为 TRUE 或者两个操作数都为 TRUE,则为 TRUE

.not.

如果右操作数为 FALSE,则为 TRUE

.eqv.

如果左操作数与右操作数具有相同的逻辑值,则为 TRUE

.neqv.

如果左操作数与右操作数具有相反的逻辑值,则为 TRUE

program testimplicit nonelogical :: a, blogical :: r_and, r_or, r_not, r_eqv, r_neqv! 初始化逻辑变量a = .true.b = .false.! 使用 .and. 操作符r_and = a .and. bprint *, 'a .and. b = ', r_and! 使用 .or. 操作符r_or = a .or. bprint *, 'a .or. b = ', r_or! 使用 .not. 操作符r_not = .not. aprint *, '.not. a = ', r_not! 使用 .eqv. 操作符(等价于)r_eqv = a .eqv. bprint *, 'a .eqv. b = ', r_eqv! 使用 .neqv. 操作符(不等价于)r_neqv = a .neqv. bprint *, 'a .neqv. b = ', r_neqv! 额外的示例,展示当 a 和 b 相同时的情况a = .true.b = .true.r_and = a .and. bprint *, 'When both a and b are true, a .and. b = ', r_andr_or = a .or. bprint *, 'When both a and b are true, a .or. b = ', r_orr_eqv = a .eqv. bprint *, 'When both a and b are true, a .eqv. b = ', r_eqvr_neqv = a .neqv. bprint *, 'When both a and b are true, a .neqv. b = ', r_neqvend program test

http://www.hkea.cn/news/528150/

相关文章:

  • 怎么做app网站seo学习网站
  • 广西建设职业技术学院官网免费的seo优化
  • 凡科网电脑版怎么做网站百度知道官网手机版
  • 贵卅省住房和城乡建设厅网站周口seo推广
  • 搭建flv视频网站seo工具查询
  • 企业展示网站 数据库设计模板自助建站
  • 房地产设计师上海seo网络优化
  • wordpress迁移打不开百度seo泛解析代发排名
  • 网站兼容性测试怎么做微信营销软件群发
  • wordpress如何设置内容页seo营销优化
  • 高端大气的网站制作南宁百度seo软件
  • 沙井营销型网站建设成人培训机构
  • 网站没有被百度收录搜索引擎排名优化公司
  • 手机网站转换小程序晋江怎么交换友情链接
  • 专业做网站的公司疫情放开最新消息今天
  • 不用写代码做网站软件长沙优化网站
  • o2o商城网站建设方案广告策划案优秀案例
  • 日照做网站的那家做的好百度网页链接
  • 建设云个人证件查询系统上海seo培训
  • 网站流量提供商杭州seo排名
  • 做装饰工程的在什么网站投标自建站
  • 地球人--一家只做信誉的网站帮忙推广的平台
  • 网站建设外包协议天津网站排名提升
  • 邯郸教育行业网站建设百度推广代理商查询
  • 政府网站有哪些网站seo最新优化方法
  • 做广告牌子seo外链工具
  • 微信页面设计网站兰州网络推广技术
  • 上门做网站搜狗站长工具
  • wordpress用户邮箱验证码百度seo搜索引擎优化培训
  • 360极速怎么屏蔽网站新闻热点大事件