SlideShare uma empresa Scribd logo
1 de 9
CONCEITOS E EXEMPLOS
DO IF/ELSE
– COMANDOS DE DECISÃO
• Uma estrutura condicional é baseada em binário, ou seja,
como programação é uma ciência exata, existem apenas
duas respostas para uma condição, que são: VERDADEIRO
OU FALSO.
Marisa
• O PHP está interpretando o código, ele encontra uma
estrutura condicional IF, então ele pergunta ao seu código,
a condição a ser comparada é verdadeira ou falsa? Com
base na resposta que o PHP vai continuar a execução do
código. Se for verdadeira a condição, ele vai percorrer por
um caminho, se for falsa por outro.
Marisa
• Um IF sempre compara pelo menos duas coisas. Vamos a
sintaxe abaixo:
Estrutura condicional IF, ELSE IF, ELSE em PHP
Kathully
• Este exemplo, onde temos duas linhas que serão
executadas somente se $a for diferente de 10, então
precisamos usar chaves, pois duas linhas vão ser
executadas neste caso.
IF
Kathully
• O else if é uma estrutura que vem abaixo de um para tentar
outra condição, caso a primeira tenha falhado. Veja o
exemplo:
ELSE IF
Como pode ver no exemplo acima, fizemos uma primeira
comparação para saber se $a é igual a 8, se não for, vai fazer
uma outra comparação, se $a é igual a 10, para só então
negar as duas tentativas, caso o $a for diferente de 10 e de 8.
Leid Daiane
COMPARAÇÃO DUPLA:
Podemos também fazer uma comparação dupla
no IF.
• Em ambos os exemplos a condição será verdadeira. No primeiro caso,
usamos E, então todas as condições devem ser verdadeiras para que a
condição geral seja verdadeira. Ou seja, $a é maior que 10 (verdadeiro)
E $b é menor que 20 (verdadeiro).
Leid Daiane
• No segundo exemplo, usamos OU, então, precisa-se que pelo menos
uma das condições seja verdadeira para que a condição geral seja
verdadeira. Ou seja, $a é maior que 10 (verdadeiro) OU $b é menor que
10 (falso, pois $b é igual a 15). Mesmo a segunda condição sendo falsa,
a condição geral é satisfeita pois uma delas é verdadeira.
Leid Daiane
DISCIPLINA:
PROGRAMAÇÃO PARA WEB AVANÇADA.
PROFESSOR:
MARCO ANTONIO
TURMA:
4º ANO, MÉDIO INTEGRADO EM INFORMÁTICA
ALUNAS:
KATHULLY, LEID DAIANE & MARISA.
Marisa

Mais conteúdo relacionado

Destaque

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 

Destaque (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Conceitos e exemplos do if

  • 1. CONCEITOS E EXEMPLOS DO IF/ELSE – COMANDOS DE DECISÃO
  • 2. • Uma estrutura condicional é baseada em binário, ou seja, como programação é uma ciência exata, existem apenas duas respostas para uma condição, que são: VERDADEIRO OU FALSO. Marisa
  • 3. • O PHP está interpretando o código, ele encontra uma estrutura condicional IF, então ele pergunta ao seu código, a condição a ser comparada é verdadeira ou falsa? Com base na resposta que o PHP vai continuar a execução do código. Se for verdadeira a condição, ele vai percorrer por um caminho, se for falsa por outro. Marisa
  • 4. • Um IF sempre compara pelo menos duas coisas. Vamos a sintaxe abaixo: Estrutura condicional IF, ELSE IF, ELSE em PHP Kathully
  • 5. • Este exemplo, onde temos duas linhas que serão executadas somente se $a for diferente de 10, então precisamos usar chaves, pois duas linhas vão ser executadas neste caso. IF Kathully
  • 6. • O else if é uma estrutura que vem abaixo de um para tentar outra condição, caso a primeira tenha falhado. Veja o exemplo: ELSE IF Como pode ver no exemplo acima, fizemos uma primeira comparação para saber se $a é igual a 8, se não for, vai fazer uma outra comparação, se $a é igual a 10, para só então negar as duas tentativas, caso o $a for diferente de 10 e de 8. Leid Daiane
  • 7. COMPARAÇÃO DUPLA: Podemos também fazer uma comparação dupla no IF. • Em ambos os exemplos a condição será verdadeira. No primeiro caso, usamos E, então todas as condições devem ser verdadeiras para que a condição geral seja verdadeira. Ou seja, $a é maior que 10 (verdadeiro) E $b é menor que 20 (verdadeiro). Leid Daiane
  • 8. • No segundo exemplo, usamos OU, então, precisa-se que pelo menos uma das condições seja verdadeira para que a condição geral seja verdadeira. Ou seja, $a é maior que 10 (verdadeiro) OU $b é menor que 10 (falso, pois $b é igual a 15). Mesmo a segunda condição sendo falsa, a condição geral é satisfeita pois uma delas é verdadeira. Leid Daiane
  • 9. DISCIPLINA: PROGRAMAÇÃO PARA WEB AVANÇADA. PROFESSOR: MARCO ANTONIO TURMA: 4º ANO, MÉDIO INTEGRADO EM INFORMÁTICA ALUNAS: KATHULLY, LEID DAIANE & MARISA. Marisa