Hi welu1805,
consider that Basic is not Pascal. If you're used to Wirth's rule of declaring (in that order) labels, constants, types, variables, procedures and functions even Delphi doesn't strictly adhere to it.
In B4A, dimming a variable is like declaring it. So dimming it twice is sort of re-declaring it where first instance is left to the garbage collector to be collected for eventual working memory reuse.
'Initialize the panels we use for the pages and put them in the container
container.Initialize
For i = 0 To 5
Dim pan As Panel
Select i
Case 0
pan = CreatePanel(TYPE_HELLO_WORLD, "Hello World")
container.AddPage(pan,"Page " & i)
Case 1
pan = CreatePanel(TYPE_SETTINGS, "Settings")
container.AddPage(pan,"Settings")
Case Else
pan = CreatePanel(TYPE_LISTVIEW, "ListView " & (i - 1))
container.AddPage(pan,"ListView " & i)
End Select
Next
In this loop the variable "pan" is declared for 6 times with the same name. Why? Can I declare it one time before the loop?
No you cant. Because you are actually creating 6 different panels. You are re-using ONE variable to reference all 6 panels. Each time you Dim it, it is creating a new panel, which is what we want. Otherwise if you put it outside the loop, you essentially have only ONE variable and ONE panel, and within the loop you keep modifying the same panel.