• 26

  • Tendo em vista que já sabemos o que é o php e como instalar um ambiente de desenvolvimento web,  podemos dar continuidade  ao nosso conteúdo com estruturas condicionais.


    Primeiramente, o que é uma condição?  Normalmente , sem perceber, usamos todos os dias, por exemplo: SE não chover vou à praia, só posso sair SE tiver dinheiro. Então ,podemos concluir que, uma expressão condicional nada mais representa do que uma sentença que deve ou não ser satisfeita para o acontecimento de um evento. Voltemos ao exemplo anterior para entender melhor :


    SE não chover irei à praia

    Podemos dividir a sentença acima em três partes:

    1)      SE ( representação de uma condição )


    2)      Não chover (sentença a ser satisfeita, mais tarde chamaremos de expressão lógica)


    3)      Irei à praia ( Evento que irá acontecer caso a sentença seja verdadeira)


    E se caso chover, não irei à praia? Não! A resposta de uma estrutura condicional só nos retorna dois possíveis valores:


    Verdadeiro, caso a sentença seja satisfeita.


    Falso, caso a sentença não seja satisfeita.


    Supondo que não esteja chovendo , veja como ficaria nosso exemplo:


    IF “não está chovendo” ( verdadeiro ) “vou à praia”. A expressão não está chovendo nos retorna a resposta como verdadeiro, então posso ir à praia.


    E se estiver chovendo,  o que faremos com a expressão?


    IF “não está chovendo” (falso) “irei à praia” ELSE ”não irei à praia” . Como Agora está chovendo não poderemos ir à praia, logo, usamos a expressão else caso a sentença não seja satisfeita.


    Já que entendemos a estrutura condicional, vamos ver como que ficaria uma estrutura em um algoritmo:


    If(“está chovendo”)


    {


    Bloco a ser executado caso a sentença seja verdadeira.

    }

    Else

    {

    bloco a ser executado caso a sentença seja falsa.

    }


    Alguns símbolos lógicos de comparação:


    ==   Igual


    >=  Maior ou igual que


    <= Menor ou igual que


    > Maior que


    < menor que


    && E


    || ou


    Qual que é a finalidade desses símbolos lógicos? Lá trás vimos que a estrutura condicional IF é composta por trêspartes. Uma condição, uma expressão lógica, e o evento que deverá ser executado caso a sentença seja verdadeira ou falsa.


    Exemplo:

    <br />
    $numero = 10; //atribuindo 10 a variável $numero<br />
    if($numero == 10) // verificando se o conteúdo da variável $numero é igual a 10<br />
    {<br />
        echo 'O número é igual a 10'; //bloco a ser executado caso a variável número seja igual a 10<br />
    }<br />
    else<br />
    {<br />
        echo 'O número é diferente de 10';// bloco a ser executado caso a variável número não for igual a 10<br /><br />
    }<br />
    

    Com isso vimos um pouco do que é uma estrutura condicional , na próxima postagem veremos outras maneiras de estar trabalhando com estruturas condicionais .

26 Comentário

  1. Eduardo Felipe

    Obrigado, pessoal da Fokusweb.
    Tirou a minha duvida, o blog está ajudando bastante !

  2. Super post, tienen que marcarlo en Digg

    [url=http://www.bad4dwn.com/]Ilias[/url]

  3. Most of the times i visit a blog i get disappointed. On the contrary,I have to say that you have done a good job here.

  4. Most what i read online is trash and copy paste but you definitely add value. Keep it like this.

  5. Good read i think your website is fantastic with superb content which i like to add to my bookmarks.

  6. One of the most useful websites I have come across for knowledge within this particular niche market. I’ll be coming back constantly for new posts.

  7. Congratulations on having one of the most sophisticated weblogs I’ve come across in some time!

  8. Hi webmaster and commenters ! The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!b Keep ‘em coming… you all do such a great job at such Concepts… can’t tell you how much I, for one appreciate all you do!

  9. It’s laborious to seek out educated folks on this matter, but you sound like you recognize what you’re talking about! Thanks

  10. you’ve got an excellent blog right here! would you wish to make some invite posts on my weblog?

  11. Very good information keep up your good work!

  12. I used to be very happy to search out this net-site.I wished to thanks to your time for this wonderful read!! I definitely enjoying each little bit of it and I have you bookmarked to check out new stuff you weblog post.

  13. This actually answered my problem, thanks!

  14. Can I just say what a aid to find somebody who actually knows what theyre speaking about on the internet. You undoubtedly know find out how to convey a problem to light and make it important. Extra people must read this and perceive this aspect of the story. I cant consider youre not more well-liked because you positively have the gift.

  15. I discovered your blog web site on google and verify a number of of your early posts. Continue to maintain up the excellent operate. I simply additional up your RSS feed to my MSN News Reader. Searching for forward to reading extra from you in a while!…

  16. There are some fascinating cut-off dates in this article however I don’t know if I see all of them heart to heart. There’s some validity but I’ll take hold opinion until I look into it further. Good article , thanks and we wish extra! Added to FeedBurner as properly

  17. The next time I read a weblog, I hope that it doesnt disappoint me as a lot as this one. I imply, I do know it was my option to read, however I truly thought youd have one thing interesting to say. All I hear is a bunch of whining about one thing that you possibly can repair in the event you werent too busy in search of attention.

  18. I was very happy to seek out this internet-site.I needed to thanks in your time for this excellent read!! I undoubtedly enjoying each little bit of it and I have you bookmarked to check out new stuff you blog post.

  19. I’d have to examine with you here. Which is not something I usually do! I take pleasure in reading a post that will make individuals think. Additionally, thanks for permitting me to remark!

  20. Nice post. I learn something more difficult on different blogs everyday. It’s going to always be stimulating to learn content from other writers and apply a little bit something from their store. I’d prefer to make use of some with the content material on my blog whether you don’t mind. Natually I’ll give you a link in your net blog. Thanks for sharing.

  21. It’s onerous to find knowledgeable people on this subject, however you sound like you already know what you’re talking about! Thanks

  22. Spot on with this write-up, I really think this website needs rather more consideration. I’ll in all probability be again to read way more, thanks for that info.

  23. very good post, i definitely love this website, keep on it

  24. very nice put up, i certainly love this web site, keep on it

  25. There’s noticeably a bundle to know about this. I assume you made certain nice factors in features also.

  26. Thanks i love your article about Estruturas Condicionais – PHP | Fokus Web

Deixa sua Opinião

© Fokusweb - Todos os direitos reservados
Av. 14, nº 498 - S. Nova Vila - Goiânia - Goiás - Brasil
+55 (62) 3661-8688
IR AO TOPO