If-else Statement (C); 2 minutes to read +2; In this article. Controls conditional branching. Statements in the if-block are executed only if the if-expression evaluates to a non-zero value (or TRUE). If the value of expression is nonzero, statement1 and any other statements in the block are executed and the else-block, if present, is skipped. If the value of expression is zero. If you are using Turbo C then most likely delay is in dos.h. But if you are using a modern compiler then there is no such function. MS-Windows has a Sleep function and.nix has sleep.
Controls conditional branching. Statements in the if-block are executed only if the if-expression evaluates to a non-zero value (or TRUE). If the value of expression is nonzero, statement1 and any other statements in the block are executed and the else-block, if present, is skipped. If the value of expression is zero, then the if-block is skipped and the else-block, if present, is executed. Expressions that evaluate to non-zero are
TRUE
a non-null pointer,
any non-zero arithmetic value, or
a class type that defines an unambiguous conversion to an arithmetic, boolean or pointer type. (For information about conversions, see Standard Conversions.)
Syntax
Example
if statement with an initializer
Visual Studio 2017 version 15.3 and later (available with /std:c++17): An if statement may also contain an expression that declares and initializes a named variable. Use this form of the if-statement when the variable is only needed within the scope of the if-block.
Example
In all forms of the if statement, expression, which can have any value except a structure, is evaluated, including all side effects. Control passes from the if statement to the next statement in the program unless one of the statements contains a break, continue, or goto.
The else clause of an if...else statement is associated with the closest previous if statement in the same scope that does not have a corresponding else statement.
if constexpr statements
Visual Studio 2017 version 15.3 and later (available with /std:c++17): In function templates, you can use an if constexpr statement to make compile-time branching decisions without having to resort to multiple function overloads. For example, you can write a single function that handles parameter unpacking (no zero-parameter overload is needed):
Delay in C: delay function is used to suspend execution of a program for a particular time.
Declaration: void delay(unsigned int);
Here unsigned int is the number of milliseconds (remember 1 second = 1000 milliseconds). To use delay function in your program you should include the 'dos.h' header file which is not a part of standard C library.
Dev C++ Download Windows 10
Delay in C program
If you don't wish to use delay function then you can use loops to produce delay in a C program.
#include<stdio.h>
int main() { int c, d; for(c =1; c <=32767; c++) for(d =1; d <=32767; d++) {} return0; }
We have not written any statement in the loop body. You may write some statements that doesn't affect logic of the program.
C programming code for delay
Dev C++ 5.11
#include<stdio.h> #include<stdlib.h>
main() { printf('This C program will exit in 10 seconds.n');
delay(10000);
return0; }
This C program exits in ten seconds, after the printf function is executed the program waits for 10000 milliseconds or 10 seconds and then it terminates.