Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Question From a Beginner

Discussion in 'Scripting' started by atvasquez04, Oct 6, 2023.

  1. atvasquez04

    atvasquez04

    Joined:
    Oct 6, 2023
    Posts:
    1
    Hi, so I am very new to scripting, and I have a question that might be stupid to those experienced in scripting. What exactly is the difference between if and for statements? I have a scripting class that showed me how to use both, but I'm still confused about which one is used for what. If someone could explain it to me, that'd be great.
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,593
    for repeats code until a condition is satisfied, can be functionally identical to while loops.
    if statements are conditionals, they will create branching paths that the code will go down.
     
    Bunny83, spiney199 and Nad_B like this.
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,843
  4. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,917
    It turns out that scripting in Unity is just regular computer programming, so any decent intro-to-programming book will cover IF's, FOR's and a bunch of other basic stuff. I'd love to recommend a good one, but the best I can do is mine, at taxesforcatses.com/TOC.html (it's either in a PDF, or a big HTML, or small HTML chunks -- all are the same).

    The main problem with it is when other things I've written on this site have made you angry. Then it can magically become full of typos and giant run-on sentences.
     
    Bunny83 likes this.