Sunday, March 2, 2014

Basic part-4 | Conditional Statements | Decisions and Loops

Hello.... Friends today we are going to discus about Conditional Statements or Decisions and looping statements. we are using these all various time in our script where we need to take a design in our scripts so let's see how these all works

  • Design making with if ,else and switch statements
  • Looping with do,while and for statements
  • Altering loops with break and continue statements
  • Nesting loops inside loop each other
php provides us no of statements to make any design like
  • if statement
  • else and elseif statements
  • switch statements
if statement : if condition is used only if a specific condition is true
if else statement : when one condition is true & other is false
if elseif else : when multiple statements are asked out of which one is true



here you can see we use three condition in different different scripts in same page & gets the out put using conditional statements
switch : selects one of many blocks of code executed

if we have multiple condition then we can use switch statement as elseif condition here elseif condition takes much time in execution then switch statement so we use here switch statement let's how switch statement works in php


here in switch statements you can see we define a variable flower & then put it in switch statements means we have various conditions of flowers & we want to select one out of all flowers then we use here switch statement & you can see it print that statement in which  we have the value of rose & print the value here

Looping in php :
In php we have 3 loop mainly do , while , & for loop let we study them one by one

do... while :  loops through of code once, repeat untill the special condition is true
for :  loops trough block of code upto a number of times
while :  loops through a block of code as long as the specified condition is true






Altering loops with break and continue statements :
now next see the loop will remain continue untill it meat with the true condition, so next we are going to study about the break & continue in loop let's take an example of for loop & see how it works


here we have to scripts see carefully in Ist script we are generating any random number in between 1 & 1000 so this rand ( ) function will help us in generating these random numbers as we refresher this script it will generate any random number each time so to clear the last value here we use the break statement so that we can use all this without error & in the second script see we are not including 4 & then again our loop will be continue then see carefully we are again in loop without any error this is all due to the help of break & continue in loops    

Nested Loops : nested loop is when loop is inside a loop it is vary important to use loop inside loops or we can say any loop inside a loop create something interesting let's see how it works 


here you can see i define a loop for loop & inside it an another loop & Ist try to increase the * on page & then decrements as shown in the output file  
Share this post

0 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

© 2017 Friends Code
Designed by cyb3r.gladiat0r
Posts RSSComments RSS
Back to top
Hack for India, Code for India, Configuration for India, Die for India !