current position:Home>Operation of if function and for function
Operation of if function and for function
2022-02-03 01:30:09 【CSDN Q & A】
include<stdio.h>
main()
{ int a=1,b;
for(b=1;b<=10;b++)
{ if(a>=8) break;
if(a%2==1) {a+=5; continue;}
a-=3;
}
printf("%d\n",b);
}
Why does the program run with an output of 4
Refer to the answer 1:
a | b |
---|---|
6 | 2 |
3 | 3 |
8 | 4 |
On the third cycle a>=8 Established direct break End of cycle
a-=3 Not every time
Refer to the answer 2:
Refer to the answer 3:
break Exit the whole cycle
continue Exit this cycle , Continue the next cycle
break and continue No subsequent code is executed
Execute before the first round b = 1; Judge b <= 10
if (a >= 8) dissatisfaction Don't execute
if (a % 2 == 1) Satisfy perform { a += 5; continue; } here continue 了 The following code will not be executed ( Here it means a -= 3;) Go straight to the next cycle At this time a=6
Execute... Before the second cycle starts b++ At this time b = 2 Judge b <= 10
if (a >= 8) dissatisfaction Don't execute
if (a % 2 == 1) { a += 5; continue; } dissatisfaction Don't execute
Then perform a -= 3; here a = 3
Execute... Before the third cycle starts b++ At this time b = 3 Judge b <= 10
if (a >= 8) dissatisfaction Don't execute
if (a % 2 == 1) { a += 5; continue; } Satisfy perform { a += 5; continue; } here continue 了 The following code will not be executed ( Here it means a -= 3;) Go straight to the next cycle At this time a=8
Execute before the fourth cycle b++ At this time b = 4 Judge b <= 10
if (a >= 8) Satisfy Carry out the following break; Then exit the whole cycle
Perform the last cardiopulmonary bypass printf("%d\n",b); here b = 4
Refer to the answer 4:
copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030130068557.html
The sidebar is recommended
- Why can't I see the absolute path of the command
- Pycharm uses the requests crawler to report the wrong requests exceptions. SSLError: HTTPSConnectionPool
- How to run multiple sleep () simultaneously in C language
- The data requested by Axios in vue3 is put into ecarts, which always shows that setoption is not defined
- What do these two for loops mean
- Java judges whether there are 30 consecutive int arrays with a length of 1000 as the growth trend
- Force deduction 221 question maximum square
- When I set this layout, I prompted an error from line 18
- The import javax. security. auth. message cannot be resolved
- The hottest Christmas tree code. one hundred and twenty-three
guess what you like
-
Open the edge browser and display "what if I can't access this page?"?
-
Running problems of java simple supermarket system
-
Is the data [10] here an address or an element? The concept is always unclear
-
Python crawling news content
-
How to deal with the problem of general code framework
-
Bubble sort, how can there be an extra number in front
-
The graph drawing algorithm of Python is described by Raptor flow chart software
-
Numpy creates an array of the specified data range
-
Python crawler obtains the data of Douban movie top250 fantasy class
-
R7-2 minimum spanning tree construction (25 points)
Random recommended
- Using burpsuite to capture the package of Pikachu shooting range SQL to inject the first level error
- Jar package conflict. I don't know where 2.29.1 came from
- About the rotation matrix on leetcode!
- The raspberry pie prompts cannot find webcams when running the command
- C + + a simple encryption, look at the warning how to modify, output nothing
- PHP composer and Vue node_ modules
- JDBC connects to the database for data deletion. The syntax is correct, but the data in the database cannot be deleted
- Java interface class program, define an interface and define two classes to implement the interface, then use the sorting method in the class, then enter an array with length of 8 in main, and call newsort with the two implementation classes as arguments
- Sort with average score, preferably bubble method
- When running the service jar, report Linux 1] + exit 1
- How to solve the problem of traceback? (Language Python)
- If an undirected graph G has 100 edges, how many vertices does the undirected graph have at least
- There was a problem calling the custom function
- The sum of a positive integer and 3 is a multiple of 5, and the difference between a positive integer and 3 is a multiple of 6. Write a program to find the minimum number that meets the conditions.
- Oracle has customized a date function. What's wrong with this writing?
- Spring boot project failed to introduce echarts
- How to solve this kind of program
- How to understand this? I didn't understand it at the beginning
- This problem requires the implementation of a function to reverse the given one-way linked list, that is, the header is set to the end of the table, and the end of the table is set to the header.
- *Isn't a numerical value? Because a is the address
- How should this program be completed
- The picture of U disk retrieved by app in Android 8.1 development board
- C language beginners' doubts, no, require recursion
- How to use bat or VBS to open Ethernet status window
- Base selection questions, C + + has just begun to learn, can someone give some ideas
- C language function problem,.?!
- Java class related problems
- What library is checkfasta in Python? Why can't you find it
- Problems encountered when deploying HTTPS certificates using docker nginx
- Why can't vs2022 run this code, but the compiler on the mobile phone can
- Java type conversion problem, is there a useful tool?
- C language function problem, confusion,.?!
- Please do me a favor and solve it
- Python learning has something you don't understand
- How does Baidu Post Bar get posts in it
- Who will prompt the board of STC89C52 if there is no professional course
- Can C language assign a value to the whole array
- How to prevent the page from sliding up and down when the wechat applet slides left and right
- Does anyone know why the information in this form can't come out? Hurry!
- Operation of strlen function