理解 For Each 循环 [英] understanding the For Each Loop
问题描述
我是脚本和编程的新手.
I'm new to scripting and programming.
在以下和类似的脚本中,我注意到存在一个objOperatingSystem"在For Each"循环中引用.我知道colSettings"是一个包含 WMI 集合的变量,但是objOperatingSystem"从何而来?
In the following and similar scripts, I noticed that there exists a 'objOperatingSystem' that is referred to in the 'For Each' loop. I understand that 'colSettings' is a variable that contains the WMI collection, but where does the 'objOperatingSystem' come from ?
请帮忙.谢谢!!!
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
Wscript.Echo "Available Physical Memory: " & _
objOperatingSystem.FreePhysicalMemory
Next
推荐答案
objOperatingSystem
是一个变量.For Each
声明了它.基本上,对于 colSettings
中的每个项目,一个名为 objOperatingSystem
的变量将被设置为当前项目,并执行 for 循环的主体.
objOperatingSystem
is a variable. For Each
declared it. Basically, for every item in colSettings
a variable named objOperatingSystem
will be set to the current item, and the body of the for loop executed.
这篇关于理解 For Each 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!