Posts

if and if else statement in C++ programming language

Image
  If and if-else statements in the C++ programming language In this blog post we will look at the basic working of if and if-else statement in C++ programming language. These if and if-else statements are also referred as conditinal statements in programming languages. But today we will study them under the context of C++ programming. In C++ programming language we use if and if-else to run a specific peace of code under one condition and another peace of code for some different condition. We also refer them as decision statements . Types of if statements in C++ programming language If we talk about types of if statements there are mainly four types 1) if statement 2) if-else statement 3) if else-if ladder statement 4) nested if statements But in this blog post we will cover the if and if-else statements. Syntax of if statement if(condition) {     //code to be executed here     }   Simple if coding example ...

Nested Loops in C Programming Language

Image
  Nested Loops in C Programming Language In programming languages, we have control statements or looping statements which are the following, 1) while-loop 2) do-while loop 3) for loop we have seen loop implementation one at a time i.e., one loop type implemented in the program. Now we will look at how to use the nested loops in the C programming language. The first thing to keep in mind is what we mean by the term nested loop. The main idea behind nested loops is to place a loop inside another loop. In this article, we are going to look at nested for loops in the C programming language. As we previously discussed we can use a loop inside another loop. So today we are going to look at how we can use a for loop inside another for loop .  Remember that if we have two for loops one for loop inside another for loop, and if both the loops are set to three iterations, then for each iteration of the outer loop the inner loop will execute three times i.e. if the outer loop runs ...

for loop in C programming language for beginners

Image
  for loop in C programming language for beginners In programming languages, we have control statements that are used to control the behavior of the programs as per user requirements. One of these control statements is in a for loop that we use to iterate the piece of code several times as per user requirement or the programmer's logic. The most common use of a for loop is traversing data structures from beginning to end. One such example of data structures is the arrays and linked lists. Basically, we use a for loop in the conditions when we are sure about the exact number of times the block of code is to be iterated. In such situations, it is preferred to use the for loop. Syntax of for loop in c: for(expression1; expression2; expression3) { // block of code to be executed here } Now if we look at the syntax of the for loop it contains for keyword and round brackets in which there are three expressions given which are separated by a semicolon (;) symbol....

while loop in c programming language

Image
  while loop in the C programming language In computer programming languages there is a concept of control flow statements. In control flow statements we specify some conditions and based on those conditions whether they are true or false we run some iterative piece of code if the condition is true and terminate the control statement if the condition is false.  There are mainly three types of control flow statements that we use in our programs to get the desired result, these three types of control statements are Three types of Control flow statements 1) do-while loop 2) while loop 3) for loop In today's post, we will discuss the while loop control statement. while loop is also known as a pre-tested loop in which before running the piece of code the condition is examined first. If the condition is true only then the while loop will execute and if the condition is false then the while loop statement terminates. In these control statements, the piece of code ...

How does a do-while loop work in the c programming language?

Image
  How does a do-while loop work in the c programming language? We use control statements in programming languages to execute code based on certain conditions. In C programming the concept of control statement is the same. These control statements iterate pieces of code multiple times according to user requirements. These iterations are controlled by some conditions that are given by the programmer or the developer. There are mainly three types of control statements or looping statements, which are, 1) do-while loop 2) while loop 3) for loop Today our main focus is on the do-while loop. We are going to look at the do-while loop and the basic syntax of the do-while loop. After that, we are going to look at an example to get a better understanding of do-while loop and its working. These loop statements increase the performance of the code. Below is the syntax of the do-while loop do{ //Write the coding part here }while(condition); Note a very important point about the do-while l...

Switch statement in c programming language

Image
  Switch statement in c programming language What Is a switch statement? The switch statement is a conditional statement that we use to run different code sections based on some conditions. The switch statement also works like the if else-if else ladder statement. As we know in the else-if ladder statement we implement multiple conditions it is exactly how the switch statement works. In the switch statement, we use the term case: that tells us about any specific condition within the switch expression area switch(expression).   What is the syntax of a switch statement in c programming switch(Some_Epression) { case value1: // insert code here break; case value2: // insert code here break; default: // insert code here } Rules and regulations of switch statement: Always remember that the expressions that are used within the switch statement i.e. switch(expression), this expression must be a single character or an integer value. As discussed earlier  case: ...

How if else-if else ladder statement works in C program.

Image
 How if else-if else ladder statement work in the C program. In C programming or any other programming language, there is a concept of control statements or conditional statements. In one of our previous blog posts, we shed some light on the if else statement in the C program. In this post, we will cover the if else-if else ladder statement, which is used when multiple conditions need to be addressed. No, we are going to look at the syntax of the if else-if else ladder statement. Syntax of if else-if else ladder statement if (condition)  { // code to be executed if the condition is true } else if ( condition ) { // code to be executed if the condition is true } else if ( condition )  { // code to be executed if the condition is true } else  { // code to be executed if none of the conditions is true } The if else-if else ladder statement is very similar to the if else statement. The main difference is the addition of an else-if part in it. In the above s...

if and if-else statement in C programming language

Image
  If and if-else statements in the C programming language When we start writing a program, if the program is simple, like adding two numbers, or a Hello World program, we don't need any decision-making in such programs.  But as the programs get complicated, they become complex, and we must make decisions. For such programs, we use conditional statements, which help in making decisions. One of the most important conditional statements is 1) if statement 2) if-else statement What is the if condition? It is a conditional statement used in almost every programming language. The if statement executes a piece of code based on a specific condition when it is true. When the condition is true, it executes the code with curly brackets. What is the syntax of if statement  The if statement has a very simple syntax, as shown below if (condition) { //This piece of code will run if the given condition is true } the above line of code tells us that when the conditio...