Python Forum
Variable definitions inside loop / could be better?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable definitions inside loop / could be better?
#3
global is not applicable here.

I think your pattern is fine. Sometimes I do this when I need to initialize a variable to one of two values based on a condition.
a = b if condition else c
If you want to know how to make sure a variable is assigned when you assign in a loop, provide an example that uses a loop.
Reply


Messages In This Thread
RE: Variable definitions inside loop / could be better? - by deanhystad - Jan-09-2024, 11:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,968 Nov-07-2023, 09:49 AM
Last Post: buran
  Help adding a loop inside a loop Extra 31 4,907 Oct-23-2022, 12:16 AM
Last Post: Extra
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,686 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  loop (create variable where name is dependent on another variable) brianhclo 1 1,186 Aug-05-2022, 07:46 AM
Last Post: bowlofred
  Passing parameters with arrays and array definitions michael_lwt 1 987 Jul-07-2022, 09:45 PM
Last Post: Larz60+
  Multiple Loop Statements in a Variable Dexty 1 1,242 May-23-2022, 08:53 AM
Last Post: bowlofred
  Cursor Variable inside Another Cursor . CX_ORacle paulo79 1 1,569 Apr-09-2022, 10:24 AM
Last Post: ibreeden
Big Grin Variable flag vs code outside of for loop?(Disregard) cubangt 2 1,220 Mar-16-2022, 08:54 PM
Last Post: cubangt
  How to save specific variable in for loop in to the database? ilknurg 1 1,192 Mar-09-2022, 10:32 PM
Last Post: cubangt
  How to add for loop values in variable paulo79 1 1,497 Mar-09-2022, 07:20 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020