What is the use of break and continue?

Break Statement

Break Statement – This statement is used to “jumps out” of a loop. The break statement breaks the loop and continues executing the code after the loop (if any).

Continue Statement

Continue Statement – This statement is used to “jumps over” one iteration in the loop. The continue statement breaks one iteration (in the loop) if a specified condition occurs and continues with the next iteration in the loop.

Escape Sequences

Character ConstantMeaning
\bBackspace
\fForm feed
\nMove to new line
\rCarriage return (Enter)
\tHorizontal Tab
\vVertical Tab
\\Print back slash
\?Print question mark
\‟Print single quote
\”Print double quote
\0Null character
Tagged : / / /

Tutorials for PHP Loops

What is Loop?

A loop is a repetition control structure. it causes a single statement or  block to be executed repeatedly What is a loop? - ppt download

A loop is an Iterative Control Structure that requires the same number of codes to be executed several times until a specific condition is met. When writing code, you may want a specific block of code to run a certain number of times. As a result, rather than applying nearly similar code lines to a script, we can employ loops.

What are the Different types of Loops?

PHP 7 Fundamental Tutorial for Beginners - PHP Loop - DevOpsSchool.com

Loops are used repeatedly to run the same piece of code as long as a given condition is met. A loop’s basic premise is to simplify recurring procedures in a programmer in order to save time and effort. PHP supports four different loop styles.

  • while – Loops through a code block as long as the given condition is true.
  • do...while – The code block running once and then is tested. State. If the condition is true, the declaration shall be repeated until the condition stated is true.
  • for – Loops via a code block before a given number is reached in the counter.
  • foreach – Loops for each unit of an array across a block of code.

Why to Use Loops?

When trying to recreate code, it might be tedious to retype or copy and paste the same code over and over again. Worse, unintentional mistakes might lead to programme malfunctions.

That’s quite a few keystrokes! What if you decide later that you want to start each statement with “The count is currently: ”? You’d have to copy it and paste it into every single line.

Fortunately, loops are a function in most programming languages that allows you to automatically repeat code before such requirements are met. Iteration is a phrase used to describe the repetition of code, and it refers to each time the code is executed. Loops will reduce the number of lines of code you write while still allowing you to update it later.

PHP is no exception, as it offers a variety of ways to repeat the execution of a code block.

This Article has cover the following PHP loop types:

  • while
  • do … while
  • for
  • foreach

There are conditions in each of these loops that prevent the loop from executing. If these requirements are not met, an endless loop will follow, and the software will never be able to quit executing the code block.

How to use loops in PHP?

In order to write effective code, any programmer needs have a thorough understanding of loops and how to use them effectively in programming.

When writing code, we must always repeat a same set of functions. Performing them one at a time would result in a higher number of lines of code and a longer duration. As a result, the software gets more difficult to understand. As a result, instead of using loops to run the code, we can use them!

Tagged : / / / / / / / / / / / / / /

How does a For loop work in JavaScript

For Loop

The for loop is frequently used, usually where the loop will be traversed a fixed number of times.

Syntax:

Nested For Loop

For loop inside for loop

Syntax:

While loop

The while loop keeps repeating an action until an associated condition returns false.

Syntax:

Nested While loop

While Loop inside While Loop

Do While Loop

The do while loop is similar to while loop, but the condition is checked after the loop body is executed. This ensures that the loop body is run at least once.

Syntax :

Nested Do While Loop

Do while inside Do while

Tagged : / / /

Define What is Loop and what are the Types with Syntax.

In this tutorial i’m going to define what is loop and what are the types with syntax with examples.

What is Loop?

Any Repeated task more than one time that is called Loop. In a loop structure, the loop asks a question. If the answer requires action, it is executed. Using loops in computer programs simplifies rather optimizes the process of coding.

Types of Loops?

  1. While Loop.
  2. Do while Loop
  3. For Loop

While Loop:- While loop is a pre-test loop. It first test a specified conditional expression and as long as the condition true action taken. While loop also known as Entry Control Loop

Syntax with example:-

<?php

$am =1;

while($am<=6;
{
echo "this is while condition: $am <br />";
$am++;
}
?>

OutPut 👇

2. Do while Loop:- Do while loop is similar to while loop but the condition is checked after the loop. This ensure that the loop body is run at least once.

<?php

$ami = 3;

do{
echo "this is Laravel Amit: $ami <br />";
$ami++;

}while($ami<=6);

?>

OutPut 👇

3. For Loop :- The for is frequently used usullay where the loop will be traversed a fixed numbers of times. A loop variable is used to control the loop

Syntax + example:-

<?php

for($num=1; $num<=5; $num++)
{
echo "this is for loop: $num <br />";
}

?>

OutPut 👇

Thanks …

Tagged : / / / /

What is Loop What are the Syntax?

In this turorial i’m going to learn about Lools, how to use and how to write.

What is loop?

A Loop is an Iterative Control Structure that involves executing the same number of code a whatever you write in the codition its used to execute the same block code again to again whenever its condition is false.

Syntax:-

while(condition){
// Code to be executed
}

EX:-

<?php    
for($n=1;$n<=10;$n++){
echo "$n<br/>";
}
?>

Result:

1
2
3
4
5
6
7
8
9
10

When to use while loops

  • While loops are used to execute a block of code until a certain condition becomes true.
  • You can use a while loop to read records returned from a database query.

Types of while loops

  • Do… while — executes the block of code at least once before evaluating the condition
  • While… — checks the condition first. If it evaluates to true, the block of code is executed as long as the condition is true. If it evaluates to false, the execution of the while loop is terminated.

The Do while loop is similar to the while loop with one important difference. The body of do while loop is executed at least once. Only then, the test expression is excuted.

do
{
// the body of the loop
}
while (testExpression);

Exmple: –

<?php
$x = 1;

do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>

Outputs:-

The number is: 1
The number is: 2
The number is: 3
The number is: 4
The number is: 5
Tagged : / / /

What is php? Define variables and Datatypes how to use it?

In this tutorial i’m going to explore about what is PHP and their datatypes and how to use of variables.
PHP is a open-source side programming language that is specially suited for web development and can be embeded to HTML. It is powerful to hold a content management system like WordPress and can be used to control user access. PHP can actually do anything related to server-side scripting or more popularly known as the backend of a website, it is more secure and reliable to be used as a server-side scripting language.

What is DataTypes?

Datatypes is a range of all different data can be given variable in PHP. It’s supports these string.

  1. String
  2. Integer
  3. Float (floating point numbers – also called double)
  4. Boolean
  5. Array
  6. Object
  7. NULL
  8. Resource

How to write datatypes in PHP?

  1. string:- string is a data type used in programming, string is a sequence of character its supports a 256-character. The simplest way to create a string is to enclose the string literal (i.e. string characters) in single quotation marks (‘), like this:

    $my_string = ‘Hello World’;

2. Integer:- An integer is a number without any decimal part.

<?php  
    $x=123;  
    echo $x;  
?>  

3. Float:- A float is a number with a decimal point as like- 2.0, 256.4, 10.358, 7.64E+5, 5.56E-5 are all floats

4. Boolean:- A boolean data can be either TRUE or FALSE. These are predefined constants in PHP.

var_dump((bool) -2);        // bool(true)
var_dump((bool) "foo");     // bool(true)
var_dump((bool) 2.3e5);     // bool(true)
var_dump((bool) array(12)); // bool(true)
var_dump((bool) array());   // bool(false)
var_dump((bool) "false");   // bool(true)


5. array:- An array stores multiple values in one single variable.

<?php
$cars = array(“Volvo”,”BMW”,”Toyota”);
var_dump($cars);
?>

6. Object:- Objects are the instances of user-defined classes that can store both values and functions. They must be explicitly declared.

7. Null:- Null is a special data type which can have only one value Null, if variable is created without a value it is automatically assigned a value of Null.

8. Resource:- Resources are not the exact data type in PHP. Resource is the storing the refrenece to functions call or refrences to external PHP resource as like database.

Tagged : / / /