Loop in programming C
There is a situation where you need to make a code a few times. In general, statements are executed sequentially. The first statement of the function is executed first, then the second sentence and so on.
Similar to other programming languages, C also provides us with many control structures and allows you to perform complex parts.
The loop allows to execute a command and a group of commands multiple times, below is the general form:
C supports the following control commands.
Loop type DescriptionWhile loop
Repeat one or more groups of commands while the given condition is true. It checks the condition before executing the loop body.For loop
Execute a series of commands multiple times and summarize the code that manages loop variables.Do . while loop
Same as the While command, except that it checks the condition at the end of the loop body.Cage the loop
You can use one or more loops in other while, for or do.while loops.Loop control commands
Loop control commands change the execution of commands from its usual range. When the execution of the command leaves a range, all automatic objects that are created within that scope are destroyed.
C supports the following loop control commands.
Control commandDescriptionBreak command
End the loop or switch command and switch to executing the loop or switch command immediately after it.Continue statement
When this command is encountered, the program will ignore the statements below it (in the same loop statement) to execute the new loop.Goto command
Go to the assigned command. However, it is advised not to use the goto command in your program.Infinite loop
A loop is an infinite loop when a condition is never false. A for loop is often used for this purpose. When you leave three conditional expressions in a for loop, you will create an infinite loop.
#include int main () { for ( ; ; ) { printf ( "Vong lap nay se chay mai mai.n" ); } return 0 ; }
When the conditional expression is absent, it is assumed to be true.
Note : You can stop (end) an infinite loop by pressing Ctrl + C.
According to Tutorialspoint
Previous lesson: Flow control in C programming
Next lesson: Function in programming C
You should read it
May be interested
- What is Loop mail?what is loop mail? to help you with this question, the following article will help you find out what loop mail is.
- For ... loop in JavaScriptthe for ... in loop is used to iterate over the properties of an object. when we haven't discussed the object yet, you may not feel comfortable with this loop. but once you understand how objects work in javascript, you will find this loop very useful.
- Loop control in JavaScriptjavascript provides high control to handle loop commands and switch commands. there may be a situation when you need to exit the loop without having to go to its endpoint. there may also be situations when you want to jump over a part of the code block and start the next loop.
- Why Microsoft Loop Can't Compare to Notionmany people have been using notion for brainstorming for years, so it's interesting to see if loop can replace it as they move deeper into the microsoft ecosystem.
- How to fix 'Please Wait for the GPSVC' loop errorthe please wait for the gpsvc loop error in windows is an annoying problem that can cause the system to get stuck at shutdown. this loop is related to group policy client service (gpsvc).
- The while loop in Shellthe while loop gives you the ability to execute a set of repetitive commands until certain conditions occur. it is often used when you need to manipulate iterative variable values.
- Until loop in Shellthe while loop is perfect for the situation where you want to execute a set of commands while some conditions are true. sometimes you need to execute a set of commands until a condition is true, then you need to use a until loop.
- Select loop in Shellthe select loop provides an easy way to create a numbered menu from which the user can select. it is useful when you want to ask the user to select one or more items from a list of options.
- For loop in Shellthe for loop works on lists of items (items). it repeats a set of commands for each item in a list.
- Event Loop in Node.jsnode.js is a single thread application, but it supports concurrent processing through event definitions and callbacks. as all node.js apis are asynchronous and single threaded, it uses the async function to maintain concurrency. node.js uses the pattern observer.