How to use Loops and Conditional Statements in C

Опубликовано: 20 Февраль 2026
на канале: Uzma Nawaz
442
29

An operator is a symbol that tells the compiler to perform specific mathematical
or logical functions. C language is rich in built-in operators and provides the
following types of operators:
Arithmetic operator
Logical operator
Relational operator
Decision-making structures require that the programmer specifies one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be
false. C programming language assumes any non-zero and non-null values as true, and if it is either zero or null, then it is assumed as false value.
If the Boolean expression evaluates to true, then the block of code inside the ‘if’ statement will be executed. If the Boolean expression evaluates to false, then the first set of code after the end of the ‘if’ statement (after the closing curly brace) will be executed. C programming language assumes any non-zero and non-null values as true and if it is either zero or null, then it is assumed as false value.
An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement.
It is always legal in C programming to nest if-else statements, which means you can use one if or else if statement inside another if or else if statements.
A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.
You may encounter situations when a block of code needs to be executed several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. Programming languages provide various control structures that allow for more complicated execution paths.
A while loop in C programming repeatedly executes a target statement as long as a given condition is true.
A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
Unlike for and while loops, which test the loop condition at the top of the loop,
the do...while loop in C programming checks its condition at the bottom of the
loop. A do...while loop is similar to a while loop, except the fact that it is guaranteed to execute at least one time.
A function is a group of statements that together perform a task. Every C
program has at least one function, which is main(), and all the most trivial
programs can define additional functions.
You can divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division is such that each function performs a specific task. A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function. The C standard library provides numerous built-in functions that your program can call. For example, strcat to concatenate two strings, memcpy to copy one memory location to another location, and many more functions. A function can also be referred as a method or a sub-routine or a procedure, etc.