In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shares with you what is the difference between conditional statements and circular statements. Xiaobian thinks it is quite practical, so share it with you to learn. I hope you can gain something after reading this article. Let's not say much. Let's take a look at it together with Xiaobian.
conditional statement IF statement
IF conditional statement syntax format is as follows:
if(condition)
action
You can also use braces to perform a set of operations:
if(condition)
{
action-1
action-1
.
.
action-n
}
The following examples are used to determine whether a number is odd or even:
$awk'BEGIN{num=10;if(num%2==0)printf"%d is even\n",num}'
The output is:
10 is an even number.
IF-ELSE statement
IF-ELSE conditional statement syntax format is as follows:
if(condition)
action-1
else
action-2
Only action-1 is required if condition is true, otherwise action-2 is executed.
$awk'BEGIN{
num=11;
if(num%2==0)printf"%d is even\n",num;
elseprintf"%d is odd\n",num
}'
The output is:
11 is odd.
IF-ELSE-IF
We can create multiple IF-ELSE statements to determine multiple conditions:
$awk'BEGIN{
a=30;
if(a==10)
print"a=10";
elseif(a==20)
print"a=20";
elseif(a==30)
print"a=30";
}'
The output is:
a=30
cycle
For
The syntax for a For loop is as follows:
for(initialisation;condition;increment/decrement)
action
The for statement first performs an initialization and then checks the condition. If the condition is true, an action is performed, followed by an increment or decrement operation. As long as the condition is true, the loop will execute. At the end of each loop, the condition is checked, and if the condition is false, the loop ends.
The following example uses the For loop to output numbers 1 to 5:
$awk'BEGIN{for(i=1;i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.